Questions
19 of 29
1What is the box model in HTML?
2Can you explain the components of the Box Model?
3What’s the difference between margin, border, padding, and content?
4How does padding affect the size of an element?
5How does margin differ from padding?
6What happens when you set negative margins?
7Does padding accept negative values? Why or why not?
8How can you visualize the box model in browser dev tools?
9What is the default box-sizing value for HTML elements?
10What does box-sizing: border-box do?
11Compare box-sizing: content-box and border-box.
12How can you make two boxes align perfectly side by side with consistent spacing?
13How do margin collapsing rules work in CSS?
14Give an example of when margin collapsing might cause layout issues.
15How can you prevent margin collapsing between parent and child elements?
16What is the difference between inline, inline-block, and block elements in terms of the box model?
17Do replaced elements (like <img>, <input>) follow the same box model rules?
18How do width and height interact with padding and border in the box model?
19Why might a layout break when switching from content-box to border-box?
20How would you fix an element that overflows its container due to box model miscalculations?
21How do you use the calc() function to compensate for padding or border widths?
22How does the box model interact with flexbox and grid layouts?
23Does the box model behave differently for absolutely positioned elements?
24How can you ensure consistent box sizing across all elements on a webpage?
25What’s the role of outline in the box model, and how is it different from border?
26How can you use the box model to achieve responsive layouts?
27How do you debug box model-related issues in a complex layout?
28Explain how min-width, max-width, and overflow affect the box model.
29How do borders affect element dimensions?
19 / 29

Why might a layout break when switching from content-box to border-box?

Understanding Layout Issues When Switching Box-Sizing Modes

When you switch an element’s box-sizing from content-box to border-box, the way CSS calculates its total width and height changes. This can cause layouts to break because the same declared width or height now includes padding and borders, reducing the space available for content.

Example: Layout Shrinking After Switch

In this example, the element’s total outer width stays at 300px after switching, but the actual content box shrinks because padding and border are now included inside that width. This can cause text wrapping, overflow, or alignment issues if other elements rely on the previous layout.

Common Reasons Layouts Break
  1. 1

    Fixed-width layouts no longer account for padding or borders, reducing content space.

  2. 2

    Elements that relied on exact pixel alignment (e.g., grid or column layouts) no longer fit correctly.

  3. 3

    Nested elements with different box-sizing values create inconsistent sizing behavior.

  4. 4

    Percent-based layouts can produce unexpected shrinkage if padding or borders are significant.

To prevent breakage, apply box-sizing: border-box consistently using a global reset and adjust widths accordingly. Many developers use a universal rule like * { box-sizing: border-box; } to keep layouts predictable.

Best Practice Reset
Key Takeaways
  1. 1

    content-box: Width and height exclude padding and border — total size grows with them.

  2. 2

    border-box: Width and height include padding and border — total size stays fixed.

  3. 3

    Switching modes without adjusting dimensions can cause layout shifts and overflow.

Difficulty: 4/10
Topics: box-sizing, layout calculations, CSS migration

Scenario Questions

0-2 years experience
  1. 1

    You have a div with width:200px and padding:20px. If you change its box-sizing from content-box to border-box, what happens to its rendered width?

  2. 2

    You need a button that stays exactly 100px wide regardless of padding. Which box-sizing would you choose and why?

  3. 3

    If you apply box-sizing: border-box globally using the * selector, what impact could that have on an existing layout that was built assuming content-box?

2-5 years experience
  1. 1

    Our responsive card component broke after we switched the project to border-box globally. Walk me through how you'd debug the issue.

  2. 2

    When converting a legacy form to use border-box, some input fields now overflow their container. What trade‑offs would you consider before deciding to keep content-box for those elements?

  3. 3

    Explain why flex container children might shrink unexpectedly after changing their box-sizing to border-box.

5-8 years experience
  1. 1

    You're leading a migration of a UI library from content-box to border-box. What steps would you take to ensure the change doesn't break existing applications, and how would you handle edge cases like SVGs or third‑party widgets?

  2. 2

    Discuss any performance or rendering implications of using border-box on a page with thousands of DOM nodes, especially on low‑end devices.

  3. 3

    How would you design a CSS utility (e.g., a Tailwind plugin) that abstracts box-sizing decisions while allowing per‑component overrides without causing layout regressions?

8+ years experience
  1. 1

    Your monorepo contains multiple products, some using content-box and others border-box. Propose a long‑term architectural strategy to unify box-sizing across the codebase while minimizing risk.

  2. 2

    For a legacy SaaS platform that serves custom themes built by external partners, how would you introduce border-box as the default without breaking third‑party themes, and what deprecation policy would you put in place?

  3. 3

    If you were to design a CSS‑in‑JS framework that automatically selects the appropriate box-sizing based on component type, what factors would you expose to developers and how would you ensure backward compatibility?

Follow-up Questions

  • What steps would you take to identify which elements broke after the switch?
  • Which CSS reset or global rule patterns help avoid these regressions?
  • Are there any component types where border-box could still cause layout issues?